package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsAccountTraceMapper;
import com.qf.pojo.DtsAccountTrace;
import com.qf.service.AccountTraceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

@Service
public class AccountTraceServiceImpl implements AccountTraceService {
    @Autowired
    private DtsAccountTraceMapper dtsAccountTraceMapper;


    @Override
    public IPage<DtsAccountTrace> findListByQuery(Integer page, Integer limit, String sort, String order, Integer[] statusArray, List<Integer> uIds) {
        return dtsAccountTraceMapper.selectPage(new Page<>(page,limit),new QueryWrapper<DtsAccountTrace>()
                .in(uIds!=null&&uIds.size()>0,"user_id",uIds)
                .in(statusArray!=null&&statusArray.length>0,"status",statusArray)
                .orderBy(!StringUtils.isEmpty(sort),"ASC".equalsIgnoreCase(order),sort));
    }

    @Override
    public void updateStatus(Integer id, Integer status, String traceMsg) {

        dtsAccountTraceMapper.updateStatus(id,status,traceMsg,new Date());

    }
}
